<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of FriendlyLinkAction
 *
 * @author Administrator
 */
import('@.Filter.SecurityAction');
import('@.Service.FriendlyLinkService');
import('@.Util.ConstantUtil');

class FriendlyLinkAction extends SecurityAction {

    function index() {
        $linkService = new FriendlyLinkService();
        $links = $linkService->listAll();

        $this->assign('links', $links);

        $this->assign('content', 'friendlyLink');
        $this->display('Admin:global');
    }

    function friendlyLinkAddPage() {
        $id = $_REQUEST['id'];


        $this->assign('module', '添加合作伙伴');
        if (!empty($id)) {
            $linkService = new FriendlyLinkService();
            $fLink = $linkService->findFLById($id);
            $this->assign('link', $fLink);
            $this->assign('module', '修改合作伙伴');
        }
        $this->assign('modules', ConstantUtil::$SEO_MODULE);

        $this->assign('content', 'friendlyLinkAdd');
        $this->display('Admin:global');
    }

    function save() {
        $id = $_REQUEST['id'];

        $linkService = new FriendlyLinkService();

        $link = $linkService->create();

        if (empty($link['id'])) {
            $linkService->insert($link);
        } else {
            $linkService->update($link);
        }


        $this->redirect('/index');
    }

    function delete() {
        $id = $_REQUEST['id'];

        $linkService = new FriendlyLinkService();

        $linkService->delete($id);

        $this->redirect('/index');
    }

    function findFLByName() {
        $name = $_POST['name'];
        $module = $_POST['module'];

        //echo($model);return;
        $linkService = new FriendlyLinkService();
//        $isNull = is_null($linkService->findFLByName($name, $module));
        //dump($isNull);
        echo (is_null($linkService->findFLByName($name, $module)));
//        echo $isNull;
    }

}

?>
